﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using V5_Common;
using System.Data;
using V5_EShop.Data;

namespace V5_EShop.Admin.Book {
    public partial class Admin_BookPub : AdminPage {

        #region Tbl_B_BookPublish开始
        protected void Page_Load(object sender, EventArgs e) {
            if (!this.IsPostBack) {
                string action = InputHelper.SetString(Request["action"]);
                switch (action) {
                    case "edit":
                        this.MultiViewList.ActiveViewIndex = 1;
                        break;
                    default:
                        Bind_DataList();
                        break;
                }
            }
        }

        private void Bind_DataList() {
            this.MultiViewList.ActiveViewIndex = 0;
            DataTable dt = V5.SQL.Query_By("*", "Tbl_B_BookPublish", string.Empty, string.Empty, 0);
            this.gvList.DataSource = dt;
            this.gvList.DataBind();
        }

        protected void Bind_DataDelete(int id) {
            this.Bind_DataList();
        }

        protected void Bind_DataEdit(int id) {
            this.MultiViewList.ActiveViewIndex = 1;
            DataRow dr = V5.SQL.Query_By("*", "Tbl_B_BookPublish", "Id=" + id, string.Empty, 1).Rows[0]; ;
            this.hfID.Value = dr["Id"].ToString();
            this.txtPubCode.Text = dr["PubCode"].ToString();
            this.txtPubName.Text = dr["PubName"].ToString();
            this.txtPubTel.Text = dr["PubTel"].ToString();
            this.txtCharIndex.Text = dr["CharIndex"].ToString();
            this.txtNote.Text = dr["Note"].ToString();
            this.lblTitle.Text = "修改";
            this.btnSave.Text = "确定保存";
        }

        protected void btnSave_Click(object sender, EventArgs e) {
            int Id = InputHelper.SetNumber(this.hfID.Value);
            int PubId = 0;
            string PubCode = this.txtPubCode.Text;
            string PubName = this.txtPubName.Text;
            string PubTel = this.txtPubTel.Text;
            string CharIndex = this.txtCharIndex.Text;
            string Note = this.txtNote.Text;
            DateTime CreateTime = DateTime.Now;
            ModelB_BookPublish model = new ModelB_BookPublish();
            if (Id > 0) {
                model = new ModelB_BookPublish(p => p.Id == Id);
            }
            model.PubId = PubId;
            model.PubCode = PubCode;
            model.PubName = PubName;
            model.PubTel = PubTel;
            model.CharIndex = CharIndex;
            model.Note = Note;

            if (Id == 0) {
                model.CreateTime = CreateTime;
                model.Add();
            }
            else {
                model.Update();
            }
            this.Bind_DataList();
        }

        protected void Pager_PageChanged(object sender, EventArgs e) {
            Bind_DataList();
        }

        protected void gvList_RowCommand(object sender, GridViewCommandEventArgs e) {
            string eName = InputHelper.SetString(e.CommandName).ToLower();
            int id = InputHelper.SetNumber(e.CommandArgument);
            switch (eName) {
                case "go":
                    Bind_DataEdit(id);
                    break;
                case "del":
                    Bind_DataDelete(id);
                    break;
            }
        }
        #endregion Tbl_B_BookPublish结束




    }
}